package mshop.com.schild_kotlin.activitys

import android.view.View
import com.wind.me.xskinloader.SkinManager
import com.wind.me.xskinloader.util.AssetFileUtils
import kotlinx.android.synthetic.main.activity_set.*
import mshop.com.schild_kotlin.R
import mshop.com.schild_kotlin.base.BaseActivity
import java.io.File

/**
 * Created by mayi on 2018/6/1.
 * @Autor CaiWF
 * @Email 401885064@qq.com
 * @TODO
 */
class SetActivity : BaseActivity(), View.OnClickListener {
    override fun getLayoutResources(): Int {
        return R.layout.activity_set
    }

    override fun initView() {
        commTitleBar("设置", View.VISIBLE, View.INVISIBLE, 0)
        skin_change.setOnClickListener(this)
        skin_reset.setOnClickListener(this)
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.skin_change -> {
                skinChange()
            }
            R.id.skin_reset -> {
                skinReset()
            }
        }
    }

    fun skinChange() {
        //将assets目录下的皮肤文件拷贝到data/data/.../cache目录下
        val saveDir = cacheDir.absolutePath + "/skins"
        val savefileName = "/skin1.skin"
        val asset_dir = "skins/otherskin-debug.apk"
        val file = File(saveDir + File.separator + savefileName)
//        if (!file.exists()) {
        AssetFileUtils.copyAssetFile(this, asset_dir, saveDir, savefileName)
//        }
        SkinManager.get().loadNewSkin(file.absolutePath)
    }

    fun skinReset() {
        SkinManager.get().restoreToDefaultSkin()
    }

    override fun getNeedRefresh(): Boolean {
        return false
    }

    override fun onRefresh() {
    }
}